package com.example.qxfw.mongodb.hy.service.impl;

import com.example.qxfw.mongodb.hy.entity.HyImageFile;
import com.example.qxfw.mongodb.hy.service.HyImageFileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;


@Service
public class HyImageFileServiceImpl implements HyImageFileService {

    @Qualifier("mongoSecondTemplate")
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public HyImageFile getByParam(String id, String tableName) {
        Query query = new Query(Criteria.where("id").is(id).and("table_name").is(tableName));
        return mongoTemplate.findOne(query, HyImageFile.class);
    }

    @Override
    public HyImageFile getById(String id) {
        return mongoTemplate.findById(id, HyImageFile.class);
    }


    @Override
    public HyImageFile save(HyImageFile hyImageFile) {
        return mongoTemplate.save(hyImageFile);
    }
}
